<?php
class UsersController extends AppController {

	var $name = 'Users';
	var $helpers = array('Form');
	
	// Cookies:
	function beforeFilter() {
		$this->cookieMonster();
	}

	function index()
		{
			 $this->set('users', $this->User->find('all'));
		}

	function add()
		{
		if (!empty($this->data['User']))
			{
				if ($this->data['User']['password'] == $this->data['User']['password_confirm'])
					{
					$this->data['User']['ID'] = $this->Uuid->generate();
					if($this->User->save($this->data['User']))
						{
							$this->flash('This User has been updated.','/user/');
						}
					} else {
						$this->flash('Passwords do not match.','/user/add');
					}
			}
		}
		
	function register()
		{
		if (!empty($this->data['User']))
			{
				if ($this->data['User']['password'] == $this->data['User']['password_confirm'])
					{
					$this->data['User']['ID'] = $this->Uuid->generate();
					if($this->User->save($this->data['User']))
						{
							$this->flash('This User has been updated.','/user/');
						}
					} else {
						$this->flash('Passwords do not match.','/user/add');
					}
			}
		}
		
	function edit($id)
		{
		if (!empty($this->data['User']))
			{
				if ($this->data['User']['password'] == $this->data['User']['password_confirm'])
					{
					$this->data['User']['ID'] = $this->Uuid->generate();
					if($this->User->save($this->data['User']))
						{
							$this->flash('This User has been updated.','/user/');
						}
					} else {
						$this->flash('Passwords do not match.','/user/add');
					}
			}
		}
		
	function delete($id) {
	
	}
	
	function view($id) {
			$this->User->ID = $id;
			$this->set('data', $this->User->read());
			$this->set('cookie_data', $this->Cookie->read());
		}

}
?>
